分析
因为要求每个人的胜率相同,则每个人的胜率为 。
考虑第一个人(骰子),如果给其一个最大值 ,那么为保持胜率,掷到其他面一定必输,所以我需要给其 个最小值(即 )。
继续考虑第二个人,第一个人的胜率已经确定,还剩 个人,则第二个人需要在 个人中保持胜率为 。同理,给其一个次大值(即 ),然后给其 个能用的最小值(即 )。
然后就可以一直这样构造了。最后如果数字给重了,说明无解。
参考代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <algorithm> #include <iostream> #include <vector> using namespace std; vector<int> a[5000]; int main() { int k, n; cin >> k >> n; int b = n, f = 1; for (int i = 1; i <= k; i++) { a[i].push_back(b); b--; for (int j = 1; j <= k - i; j++) { a[i].push_back(f); f++; } } if (f > b + 1) cout << "NO"; else { while (f <= b) { a[k].push_back(f); f++; } for (int i = 1; i <= k; i++) { sort(a[i].begin(), a[i].end()); cout << a[i].size() << " "; for (int j : a[i]) cout << j << " "; cout << "\n"; } } return 0; }
|